package com.dfrobot.demo.controller;

import com.dfrobot.demo.domain.entity.User;
import com.dfrobot.demo.dto.UserDTO;
import com.dfrobot.demo.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@Slf4j
@RequestMapping(value = "/user", produces = "application/json;charset=UTF-8")
public class UserController {
    @Autowired
    private UserService userService;

    @GetMapping(value = "/test/{id}/name/{name}")
    public String abc(@PathVariable Integer id, @PathVariable String name) {
        log.info("this is test,id:{},name:{}", id, name);
        return "123";
    }

    @GetMapping("/list")
    public List<User> getUserList() {
        List<User> userList = this.userService.getUserList();
        return userList;
    }

    @GetMapping(value = "/test1")
    public List<UserDTO> test1() {
        //String result = this.userService.test(111, "Seifer");
        List<UserDTO> userDTOList = new ArrayList<>();
        UserDTO userDTO = new UserDTO();
        userDTO.setUserId(100);
        userDTO.setUserName("Seifer");
        userDTOList.add(userDTO);
        return userDTOList;
    }
}
